import os

from dotenv import load_dotenv
from langchain.chains.question_answering.map_reduce_prompt import messages
from langchain_core.messages import SystemMessage, HumanMessage
from langchain_core.output_parsers import StrOutputParser
from langchain_openai import AzureChatOpenAI

from chat.azure_chat import llm_model

load_dotenv()
model = AzureChatOpenAI(
    # openai_api_key=
    # openai_api_base=os.getenv("AZURE_OPENAI_ENDPOINT"),
    api_key = os.getenv("AZURE_OPENAI_API_KEY"),
    azure_endpoint = os.getenv("AZURE_OPENAI_ENDPOINT"),
    azure_deployment = os.getenv("AZURE_OPENAI_DEPLOYMENT_NAME"),
    api_version = os.getenv("AZURE_OPENAI_API_VERSION"),
    temperature = 0.7
)
msg = [
    SystemMessage(content="将下面内容从英文翻译成中文"),
    HumanMessage(content="It's a nice today")
]

parser = StrOutputParser()
result = model.invoke(msg)
print(f"raw data: {result}")

response = parser.invoke(result)
print(f"使用parser处理之后的data: {response}")
